'use strict';
const {timestamps} = require('../utlis/helper')
module.exports = function (sequelize, DataTypes) {
    let UserInfo = sequelize.define('user_info', {
        id: {
            type: DataTypes.UUID,
            primaryKey: true,
            allowNull: false,
            defaultValue: DataTypes.UUIDV1
        },
        userId: {
            type: DataTypes.UUID,
            allowNull: false
        },
        realName: {
            type: DataTypes.STRING,
            allowNull: false
        },
        mobile: {
            type: DataTypes.STRING(11),
            allowNull: false
        },
        birthday: {
            type: DataTypes.DATE,
            allowNull: true
        },
        signature: {
            type: DataTypes.STRING,
            allowNull: true
        },
        createdAt: {
            type: DataTypes.INTEGER(11),
            allowNull: true
        },
        updatedAt: {
            type: DataTypes.INTEGER(11),
            allowNull: true
        }
    }, {
        indexes:[
            // Create a unique index on email
            {
                unique: true,
                fields: ['userId']
            },
            {
                unique: true,
                fields: ['mobile']
            }
        ],
        hooks: {
            beforeCreate(instances, options) {
                instances.createdAt = instances.updatedAt = timestamps()
            },
            beforeUpdate(instances, options) {
                instances.updatedAt = timestamps()
            },
            beforeBulkCreate: function (instances, options) {
                options.individualHooks = true;
            },
            beforeBulkUpdate: function (options) {
                options.individualHooks = true;
            }
        }
    })
    return UserInfo
}